<?php
/**
 * JosemUserServ.php
 *
 * @copyright   2024 jsjsem.cn - All Rights Reserved
 * @link        https://www.jsjsem.cn/
 * @author      stiffer.chen <service@josen.info>
 * @created     2024-04-19 14:36:10
 * @modified    2024-04-19 14:36:10
 *
 */

namespace App\Services;

use App\Repositories\JosemUserRepo;

class JosemUserServ
{
    /**
     * 账号重置密码
     *
     * @param $mobile string 手机号码
     * @param $smsCode string 手机验证码
     * @param $password string 密码
     * @return void
     * @throws \Exception
     */
    public function resetPassword(string $mobile, string $smsCode, string $password)
    {
        if (!JosemUserRepo::exist($mobile)) {
            throw new \Exception('手机号不存在');
        }
        $verifyCodeService = new VerifyCodeService($mobile);
        $verifyCodeService->validateCode($smsCode);

        // reset password for user
        JosemUserRepo::resetPassword($mobile, $password);
    }
}